package com.newdjk.newdoctor.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import com.newdjk.newdoctor.MyApplication;
import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.entity.AppLicationEntity;
import com.newdjk.newdoctor.utils.AppLicationUtils;

import java.util.List;

public class SelectFunctionAdapter extends BaseQuickAdapter<AppLicationEntity, BaseViewHolder> {
    private String TAG = "MyDiagnoseImageAdapter";
    private Gson mGson;
    private List<AppLicationEntity> datalist;
    private int type = 0;
    private OnItemEditedClickListener listener;


    public SelectFunctionAdapter(@Nullable List<AppLicationEntity> data) {
        super(R.layout.application_item, data);

        datalist = data;
        mGson = new Gson();
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, final AppLicationEntity item) {

        helper.setText(R.id.tv_desc, item.getAppDesc() + "");

        ImageView avatar = helper.getView(R.id.im_appicon);
        Glide.with(MyApplication.getContext())
                .load(AppLicationUtils.getimageID(item.getAppDesc()))

                //.diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(avatar);

        View view = helper.getView(R.id.im_edit);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              if (listener!=null){
                  listener.OnItemEdited(helper.getAdapterPosition());
              }
            }
        });

    }

    public void setOnEditListener(OnItemEditedClickListener listener) {

        this.listener = listener;
    }


    public interface OnItemEditedClickListener {
        /**
         * callback method to be invoked when an item child in this view has been click
         *
         * @param adapter  BaseQuickAdapter
         * @param view     The view whihin the ItemView that was clicked
         * @param position The position of the view int the adapter
         */
        void OnItemEdited(  int position);
    }
}
